//
//  WHButtonBackgroundCell.m
//  WHPersonalData
//
//  Created by hyf on 2025/4/26.
//  Copyright © 2025 mac. All rights reserved.
//

#import "WHButtonBackgroundCell.h"
#import "SDAutoLayout.h"
#import "WHHeaderButtonModel.h"

@interface WHButtonBackgroundCell()
@property(nonatomic,strong)UIView *mbgView;
@property(nonatomic,strong)UIView *mRounbgView;
@property(strong,nonatomic)UILabel *mNameLabel;

/// cell的高度 总高度的一半 留出上下边距
@property (nonatomic,assign)CGFloat WHButtonBorderCellHeight;

@property (strong, nonatomic) WHHeaderButtonModel*cateModel;

@end
@implementation WHButtonBackgroundCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.WHButtonBorderCellHeight = frame.size.height*2/3;
        [self setViewChilds];
    }
    return self;
}

-(void) setViewChilds{
    UIView *bgView =[[UIView alloc] init];
    _mbgView = bgView;
    [self.contentView addSubview:_mbgView];
    
    UIView *bgRounView =[[UIView alloc] init];
    bgRounView.layer.cornerRadius  = 5;
    bgRounView.backgroundColor  = [UIColor blackColor];
    _mRounbgView = bgRounView;
    [_mbgView addSubview:_mRounbgView];
    
    UILabel *name = [[UILabel alloc] init];
    name.textAlignment = NSTextAlignmentCenter;
    name.font = [UIFont systemFontOfSize:12];
    name.numberOfLines = 1;
    _mNameLabel = name;
    [_mRounbgView addSubview:_mNameLabel];
    
}

-(void) setViewChildsAttr{
    _mbgView
    .sd_layout
    .topSpaceToView(self.contentView, 0)
    .bottomSpaceToView(self.contentView, 0)
    .leftSpaceToView(self.contentView, 0)
    .rightSpaceToView(self.contentView, 0);
    
    _mRounbgView
    .sd_layout
    .heightIs(self.WHButtonBorderCellHeight)
    .leftSpaceToView(_mbgView, 5)
    .rightSpaceToView(_mbgView, 5)
    .centerYEqualToView(_mbgView);

    _mNameLabel
    .sd_layout
    .leftSpaceToView(_mRounbgView, 0)
    .rightSpaceToView(_mRounbgView, 0)
    .heightIs(self.WHButtonBorderCellHeight);

}

- (void)setCateModel:(WHHeaderButtonModel *)cateModel{
    _cateModel = cateModel;
    [self setViewChildsAttr];
    if(cateModel.isSel){
        if(cateModel.selColor){
            self.mNameLabel.textColor = cateModel.selColor;
        }else{
            self.mNameLabel.textColor = RGBColor(28,187,240);
        }
        if(cateModel.selBgColor){
            self.mRounbgView.backgroundColor  = cateModel.selBgColor;
        }else{
            self.mRounbgView.backgroundColor  = [UIColor blackColor];
        }
        if(cateModel.selFont)
        {
            self.mNameLabel.font = cateModel.selFont;
        }else{
            self.mNameLabel.font = [UIFont systemFontOfSize:12];
        }
    }else{
        if(cateModel.noSelColor){
            self.mNameLabel.textColor = cateModel.noSelColor;
        }else{
            self.mNameLabel.textColor = RGBColor(221, 218, 218);
        }
        if(cateModel.noSelBgColor){
            self.mRounbgView.backgroundColor  = cateModel.noSelBgColor;
        }else{
            self.mRounbgView.backgroundColor  = [UIColor blackColor];
        }
        if(cateModel.font)
        {
            self.mNameLabel.font = cateModel.font;
        }else{
            self.mNameLabel.font = [UIFont systemFontOfSize:12];
        }
    }
    self.mNameLabel.text = cateModel.title;
}


@end
